package tech.aistar.day02;

import java.nio.charset.StandardCharsets;

public class StringDemo {
    public static void main(String[] args) {
        String a="admin";
        String b="admin";
        System.out.println(a==b);

        String x=new String("abc");
        String y=new String("abc");
        System.out.println(x==y);

        System.out.println(x.equals(y));//true

        String z = "abc";
        System.out.println(x == z);//false

        //让x强制指向串池中的"abc";
        System.out.println(x.intern() == z);//true

        String o1 = "a";
        String o2 = o1 + "b";// 底层JVM指令 -> new StringBuilder对象   <- o2

        String o4 = "a" + "b";// "ab"整体 -> ldc
        String o3 = "ab";
        System.out.println(o2 == o3);//false
        System.out.println(o4 == o3);//true

        final String f = "a";//final=>不可变的
        String f2 = f + "b"; // "ab" => 常量池
        System.out.println(o3 == f2);//true

        //API方法
        //1 charAt
        String demo="abcdefg";
        String demo1="abcdefg123";
        System.out.println(demo.charAt(1));
        //2 codePointAt(ASCⅡ)
        System.out.println(demo.codePointAt(1));
        //3 codePointBefore
        System.out.println(demo.codePointBefore(1));
        //4 codePointCount
        System.out.println(demo.codePointCount(0,6));
        //5 compareTo
        System.out.println(demo.compareTo(demo1));
        //6 compareToIgnoreCase
        String demo2="abcdefG";
        System.out.println(demo.compareToIgnoreCase(demo2));
        //7 concat
        String demo3="abcdefg";
        System.out.println(demo3.concat("123"));
        //8 contains
        System.out.println(demo.contains("abc"));
        System.out.println(demo.contains("123"));
        //9 contentEquals
        System.out.println(demo.contentEquals("abcdefg"));
        System.out.println(demo.contentEquals("abcdefgh"));
        //10 copyValueOf
        char[] c={'a','b','c'};
        String demo4="";
        String demo5="";
        demo4=demo4.copyValueOf(c);
        System.out.println(demo4);
        demo5=demo5.copyValueOf(c,1,2);
        System.out.println(demo5);
        //11 endsWith
        System.out.println(demo.endsWith("g"));
        //12 equals
        System.out.println(demo.equals(demo3));
        //13 equalsIgnoreCase
        String demo6="ABCDEFG";
        System.out.println(demo.equalsIgnoreCase(demo6));
        //14 getBytes
        byte[] byte1=demo.getBytes();
        System.out.println(byte1);
        //15 getChars
        char[] c1=new char[10];
        demo.getChars(0,4,c1,0);
        System.out.println(c1);
        //16 hashcode
        System.out.println(demo.hashCode());
        //17 indexOf
        System.out.println(demo.indexOf('a'));
        System.out.println(demo.indexOf("abc",0));
    }
}
